package com.zgc.simpleholiday.utils;

import org.springframework.util.SerializationUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Objects;

public class SerUtil {

    public static <T> T deserialization(String filePath) throws IOException {
        byte[] bytes = Files.readAllBytes(new File(filePath).toPath());
        return (T) SerializationUtils.deserialize(bytes);
    }

    public  static <T>  void serialization(T t, String filePath) throws IOException {
        byte[] bytes = SerializationUtils.serialize(t); //TODO 报错调试
        Files.write(new File(filePath).toPath(), Objects.requireNonNull(bytes));
    }
}
